package com.chenyun.common.enums;

/**
 * 缓存相关的枚举
 */
public enum CacheEnum {

    imgCode_key("imgCode","图片验证码缓存key"),

    ;

    CacheEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private String code;
    private String msg;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    // 根据value返回枚举类型,主要在switch中使用
    public static CacheEnum getByValue(String value) {
        for (CacheEnum code : values()) {
            if (value.equals(  code.getCode()) ) {
                return code;
            }
        }
        return null;
    }


    /**
     * 通过枚举的code值加上传入的value值组装cache的key
     * @param cacheEnum
     * @param value
     * @return
     */
    public  static String getKey(CacheEnum cacheEnum,String value){
       return  cacheEnum.getCode()+":"+value;
    }

}
